#include "monster_lib.c"
int move_npc(object mem, object who);
object create_npc();

int move_npc(object mem, object who)
{
	mapping room_map;
	string *room_arr, room_temp;
	object room;
	object jingling;
	int count = 0, max;
	
	jingling = new(__DIR__"jingling");
	
	room_map = mem->query("count");
	room_arr = keys(room_map);
	
	max = 5 + random(3);
	
	foreach(room_temp in room_arr)
	{
		room = room_map[room_temp];
		if ((random(3) != 0) && count < max)
		{
			count++;
			create_npc()->move(room);
		}
	}
	if (who->query_temp("zhongqiu") < 4)
	{
		jingling->move(room_map[room_arr[random(sizeof(room_arr))]]);
		who->add_temp("zhongqiu", 1);
	}
}

object create_npc()
{
	mapping npc_map;
	string *npc_arr, npc_temp;
	object npc;
	
	npc = new(__DIR__"monster");
	
	npc_map = npc_lib[random(sizeof(npc_lib))];
	npc_arr = keys(npc_map);
	
	foreach(npc_temp in npc_arr)
	{
		npc->set(npc_temp, npc_map[npc_temp]);
		npc->reincarnate();
	}
	
	return npc;
}